<template>
  <div id="app">
    <!-- set progressbar -->
    <vue-progress-bar></vue-progress-bar>
    <router-view></router-view>
  </div>
</template>

<style lang="scss">
@import '../scss/index';
body {
  margin: 0;
  font-size: 2rem;
  font-family: -apple-system, BlinkMacSystemFont,
               'avenir next', avenir,
               helvetica, 'helvetica neue',
               Ubuntu,
               'segoe ui', arial,
               sans-serif;
}
.page {
  /* nesting for the need to test postcss */
  code {
    background-color: #f0f0f0;
    padding: 3px 5px;
    border-radius: 2px;
  }
}
</style>
<script>
  import axios from 'axios'
  import { MessageBox } from 'element-ui'
  import { mapState } from 'vuex'

  export default {
    data () {
      return {}
    },
    beforeMount () {
      axios.interceptors.request.use(request => {
        // console.log('Starting Request', request)
        return request
      })

      axios.interceptors.response.use(response => {
        const responseData = response.data
        if (responseData.errmsg === '您的登录会话已经过期，请重新登录！') {
          if (this.switchSite === false) {
            MessageBox({
              title: '请注意:',
              message: responseData.errmsg,
              confirmButtonText: '确定',
              type: 'error'
            }).then(() => {
              window.location.href = '/platform/user/login'
            }).catch(() => {
              window.location.href = '/platform/user/login'
            })
          } else {
            window.location.href = '/platform/user/login'
          }
        }
        console.log('Response:', response)
        return response
      })
    },
    computed: {
      ...mapState({
        switchSite: state => state.site.switch_site
      })
    }
  }
</script>
